package com.team7.sso.controller;

import com.team7.sso.service.MemberService;
import com.team7.sso.service.UserService;
import com.team7.sso.vo.CommonResult;
import com.team7.sso.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @program: team7-Object
 * @description:
 * @author: 杨海涛
 * @create: 2021-10-23 16:02
 **/
@RestController
@RequestMapping("/sso/admin")
@Api("后台用户登录的接口")
public class LoginUserController {

    @Autowired
    private UserService userService;

    @Autowired
    private MemberService memberService;

    @PostMapping("/login")
    public CommonResult loginByUserNameAndPassword(@ApiParam("登录者的账号和密码")@RequestBody LoginVo loginVo){
        return userService.loginByUserNameAndPassword(loginVo);
    }

    @PostMapping("/qianLogin")
    public CommonResult loginByMobileAndPassword(@ApiParam("客户端登录者的账号和密码")@RequestBody LoginVo loginVo){
        return memberService.loginByMobileAndPassword(loginVo);
    }

    @GetMapping("updateUserPassword/{oldPassword}/{newPassword}/{salt}")
    public Map<String, String> updateUserPassword(@PathVariable("oldPassword")String oldPassword, @PathVariable("newPassword")String newPassword, @PathVariable("salt")String salt){
        return userService.updateUserPassword(oldPassword,newPassword,salt);
    }

    @GetMapping("getPassword/{password}/{salt}")
    public Map<String, String> getPassword( @PathVariable("password")String password, @PathVariable("salt")String salt){
        return userService.getPassword(password,salt);
    }

}
